package com.example.mqtt.mapper;

import com.example.mqtt.entity.QueueSequence;
import jakarta.websocket.server.PathParam;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/5/4 22:59
 **/
@Mapper
public interface QueueSequenceMapper {
    @Insert("""
insert into penguin_queuing_sequences (sequence_id, username, phone, rfid_tag, daily_order, service_date, service_status,
 create_time, update_time, operator_id)
values (#{sequenceId}, #{username}, #{phone}, #{rfidTag}, #{dailyOrder}, #{serviceDate}, #{serviceStatus}, now(), now(), null)
""")
    void saveQueueSequence(QueueSequence queueSequence);

    @Select("""
select * from penguin_queuing_sequences where sequence_id = #{sequenceId}
""")
    QueueSequence queryQueueSeqById(String sequenceId);

    @Select("""
select * from penguin_queuing_sequences where service_date = #{targetDate} order by daily_order asc;
""")
    List<QueueSequence> queryQueueSeqByTargetDate(String targetDate);

    @Update("""
update penguin_queuing_sequences set service_status = #{newStatus} where rfid_tag = #{rfidTag}
""")
    void updateQueueSeqStatus(@Param("rfidTag") String rfidTag,
                              @Param("newStatus") Integer newStatus);

    @Select("""
select * from penguin_queuing_sequences order by create_time desc
""")
    List<QueueSequence> queryQueue();
}
